home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / spiderweb / tools / excerpt / section.c < prev   
C/C++ Source or Header  |  1991-01-14  |  2KB  |  71 lines

  1. #include <stdio.h>
  2. main() {
  3.   FILE * ttyin, *ttyout;
  4.   char buffer[800];
  5.    char ttybuffer[80];
  6.   int line;
  7.   int level,skiplevel;
  8.   int skipping=0;
  9.   int all=0;
  10.   char *name = buffer;
  11.  
  12. #define barf fprintf(stderr,"section: file error\n"); exit(1);
  13.   if (NULL==(ttyin=fopen("/dev/tty","r"))) {
  14.     barf;
  15.   }
  16.   if (NULL==(ttyout=fopen("/dev/tty","w"))) {
  17.     barf;
  18.   }
  19.   printf("1 ");
  20.   level=skiplevel=99;
  21.   while (gets(buffer)!=NULL) {
  22.     sscanf(buffer,"%d", &line);
  23.     if (gets(buffer)==NULL) {barf;}
  24.     sscanf(buffer,"%d", &level);
  25.     if (gets(buffer)==NULL) {barf;}
  26. /* fprintf(ttyout,"Checking level %d section on line %4d \"%s\"\n", 
  27. /*         level, line, name);
  28. /* fprintf(ttyout,"skipping=%d and skiplevel=%d\n", skipping,skiplevel);
  29.  */
  30.     if ((!skipping) || level <= skiplevel) {
  31.       if (all && level>skiplevel) {
  32.     fprintf(ttyout,"             includes \"%s\"...\n", name);
  33.       } else {
  34.     int querycount=0;
  35.     skiplevel=level;
  36.     *ttybuffer='X';
  37.     while (*ttybuffer !='y' && *ttybuffer != 'n' && *ttybuffer != 'a'
  38.            && *ttybuffer != '\0') {
  39.       fprintf(ttyout,"Print level %d section \"%s\" [ayn]? ", 
  40.           level, name);
  41.       fflush(ttyout);
  42.       fgets(ttybuffer,80,ttyin);
  43.       if (++querycount>10) {
  44.         fprintf(ttyout,
  45.             "If you won't type 'y', 'n', 'a', or <CR>, I'll just quit\n");
  46.         exit(8);
  47.       }
  48.         
  49.     }
  50.     if (*ttybuffer=='n') {
  51.       if (!skipping) printf ("%d ", -line);
  52.       skipping = 1;
  53.       all = 0;
  54.     } else if (*ttybuffer=='a' || *ttybuffer=='\0') {
  55.       if (skipping) printf ("%d ", line);
  56.       skipping = 0;
  57.       all=1;
  58.     } else {
  59.       if (skipping) printf ("%d ", line);
  60.       skipping = 0;
  61.       all=0;
  62.     }
  63.       }    
  64.     }
  65.   }
  66. }
  67.   
  68.   
  69.   
  70.  
  71.